<%

command = request("command")

select case command
case "rmmsg"
	filename = request("file")
	source = Server.MapPath(".\input\4kabelkrant") & "/" & filename
	target = Server.MapPath(".\input\archived") & "/" & filename
	set fs = CreateObject("Scripting.FileSystemObject")
	nr = 0
	originaltarget = target
	while fs.fileexists(target)
		nr = nr + 1
		target = originaltarget & "_" & cstr(nr)
	wend
	fs.movefile source, target
	set fs = nothing
	response.redirect "messages.asp"
case "msgcompose"
	header
	%><h1>Bericht schrijven</h1>
	<form name="msgForm" method="post" action="action.asp?command=sendmsg">
		<table>
			<tr><td>Van:</td><td><input type="text" name="van" size="25" value="<%=session("loggedUser")%>"></td></tr>
			<tr><td>Aan:</td><td><input type="text" name="aan" size="25"></td></tr>
			<tr><td>Onderwerp:</td><td><input type="text" name="onderwerp" size="35"></td></tr>
			<tr><td colspan="2"><textarea wrap="hard" rows="6" cols="55" name="body"></textarea></td></tr>
			<tr><td colspan="2" align="right"><input type="button" value="Annuleren" onclick="history.go(-1);">&nbsp;<input type="submit" value="Verzenden"></td></tr>
		</table>
	</form>

	<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    document.msgForm.aan.focus();
    //-->
    </SCRIPT><%
	footer
case "sendmsg"
	onderwerp = request.form("onderwerp")
	if trim(onderwerp) = "" then onderwerp = "bericht"
	target = Server.MapPath(".\input\4kabelkrant") & "/" & onderwerp
	set fs = CreateObject("Scripting.FileSystemObject")
	originaltarget = target
	while fs.fileexists(target & ".txt")
		nr = nr + 1
		target = originaltarget & "_" & cstr(nr)
	wend
	set file = fs.createtextfile(target & ".txt")
	file.writeline "Van: " & request.form("van")
	file.writeline "Aan: " & request.form("aan")
	file.writeline "Onderwerp: " & request.form("onderwerp")
	file.writeline "Datum: " & now()
	file.writeline "-----------------------------------------------------"
	file.writeline request.form("body")
	file.close
	set file = nothing
	set fs = nothing
	response.redirect ("editor.asp")
case else
	response.write command & ": unknown command"
end select

sub header
	%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title><%=PRODUCTNAME%> - Action</title>
	<LINK REL="stylesheet" TYPE="text/css" HREF="style/editor.css">
</head>

<body><%
end sub

sub footer
	%></body>
</html><%
end sub

%>